…
…
library("xml2")
library(tidyr)
## Warning: package 'tidyr' was built under R version 3.5.2
library(leaflet)
library(mapview)
library(raster)
## Warning: package 'raster' was built under R version 3.5.2
## Loading required package: sp
##
## Attaching package: 'raster'
## The following object is masked from 'package:tidyr':
##
## extract
library(sp)
library(sf)
## Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
library("stringr")
## Warning: package 'stringr' was built under R version 3.5.2
library("tsibble")
##
## Attaching package: 'tsibble'
## The following objects are masked from 'package:raster':
##
## select, stretch
## The following object is masked from 'package:stats':
##
## filter
library("xts")
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following object is masked from 'package:tsibble':
##
## index
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Attaching package: 'xts'
## The following object is masked from 'package:leaflet':
##
## addLegend
library("tsbox")
library("plotly")
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.5.2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:raster':
##
## select
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
OMfile <- read_xml("http://sk.ise.cnr.it/observations/sos/kvp?service=SOS&version=2.0.0&request=GetObservation&offering=offering:http://sp7.irea.cnr.it/sensors/sk.ise.cnr.it/procedure/SAFAS/SAFAS-UVmc2/noSerialNumberDeclared/2015042820079863/observations&observedProperty=http://vocab.nerc.ac.uk/collection/P01/current/MDMAP004/&procedure=http://sp7.irea.cnr.it/sensors/sk.ise.cnr.it/procedure/SAFAS/SAFAS-UVmc2/noSerialNumberDeclared/2015042820079863&featureOfInterest=http://sp7.irea.cnr.it/sensors/sk.ise.cnr.it/foi/SSF/SP/EPSG:4326/46.17583/8.19111&MergeObservationsIntoDataArray=true")
type <- xml_attr(xml_find_all(OMfile, ".//om:type"), "href")
procedure <- xml_attr(xml_find_all(OMfile, ".//om:procedure"), "href")
observedProperty <- xml_attr(xml_find_all(OMfile, ".//om:observedProperty"), "href")
foi <- xml_attr(xml_find_all(OMfile, ".//om:featureOfInterest"), "href")
foiTitle <- xml_attr(xml_find_all(OMfile, ".//om:featureOfInterest"), "title")
uom <- xml_attr(xml_find_all(OMfile, ".//ns:uom"), "code")
values <- xml_find_all(OMfile, ".//ns:values/text()")
numValues <- xml_find_all(OMfile, ".//ns:Count/ns:value/text()")
v <- strsplit(as.character(values), ";")
m <- matrix(unlist(v), nrow = as.numeric(as.character(numValues)), byrow=FALSE)
d <- as.data.frame(m)
a <- as.data.frame(str_split_fixed(d$V1, ",", 2))
colnames(a) <- c('time', 'results')
a$results <- as.double(a$results)
ts_tsibble(a)
## [value]: 'results'
## # A tsibble: 79 x 2 [1D] <Europe/Berlin>
## time results
## <date> <dbl>
## 1 1984-08-14 23
## 2 1984-10-25 3
## 3 1985-08-07 22
## 4 1985-09-25 1
## 5 1985-10-23 2
## 6 1986-07-30 28
## 7 1986-10-14 37
## 8 1987-09-23 1
## 9 1988-11-02 3
## 10 1989-10-17 1
## # … with 69 more rows
…
plot_ly(data = a, x = ~time, y = ~results, type = "scatter", mode = "lines", name = 'precipitation measure') %>%
layout(
xaxis = list(
title = ""
),
yaxis = list(
title = 'precipitation measure (mm)'
),
legend = list(
x = 0.9,
y = 0.9,
bgcolor = "#FFF",
bordercolor = "#000",
borderwidth = 1
),
showlegend = TRUE)
This code is being developed by Alessandro Oggioni (IREA-CNR), and it is released under the GNU General Public License version 3 (GPL‑3).